<script setup lang="ts">
// import { RouterLink, RouterView } from 'vue-router'
// import HelloWorld from './components/HelloWorld.vue'
import { ref, onMounted } from 'vue'
import BookAdd from './components/BookAdd.vue'
import { list, init } from './http/index'
const searchVal = ref()
const enterSearch = () => {}
const load = async () => {
  let data = (await list(searchVal.value)).data
  tableData.value = data
}
const initApi = async () => {
  let data = (await init()).data
  tableData.value = data
}
const handleAdd = () => {
  isShow.value = true
}
const handleEdit = (index: number, row: any) => {
  isShow.value = true
  editData.value = row
}
const handleDelete = (index: number, row: any) => {}
const tableData = ref([])
const isShow = ref(false)
const editData = ref({})
onMounted(async () => {
  await load()
  // await initApi()
})
</script>

<template>
  <RouterView />
  <!-- <header>
    <img alt="Vue logo" class="logo" src="@/assets/logo.svg" width="125" height="125" />

    <div class="wrapper">
      <HelloWorld msg="You did it!" />

      <nav>
        <RouterLink to="/">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
      </nav>
    </div>
  </header>

  <RouterView /> -->
  <!-- <div class="main">
    <el-row>
      <el-col :span="12">
        <el-input v-model="searchVal" @keyup.enter="enterSearch"></el-input>
      </el-col>
      <el-col :span="12">
       <el-button @click="load" type="primary">查询</el-button>
       <el-button @click="handleAdd">新增</el-button>
      </el-col>
    </el-row>
    <el-table :data="tableData" style="width: 100%;">
      <el-table-column type="index" width="50"></el-table-column>
      <el-table-column label="名称" prop="BookName" width="150"></el-table-column>
      <el-table-column label="作者" prop="Author" width="150"></el-table-column>
      <el-table-column label="类别" prop="TypeName" width="150"></el-table-column>
      <el-table-column label="备注" prop="Remarks" width="150"></el-table-column>
      <el-table-column label="操作">
        <template #default="scope">
          <el-button size="small" @click="handleEdit(scope.$index,scope.row)">编辑</el-button>
          <el-button size="small"  @click="handleDelete(scope.$index,scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <book-add :isShow="isShow" :editData="editData"></book-add>
  </div> -->
</template>

<style scoped>
.main {
  width: 100%;
  height: 300px;
  /* display: flex;
  align-items: center;
  justify-content: center; */
}
.el-button {
  margin-left: 20px;
}
.el-table {
  width: 100%;
}
header {
  line-height: 1.5;
  max-height: 100vh;
}

.logo {
  display: block;
  margin: 0 auto 2rem;
}

nav {
  width: 100%;
  font-size: 12px;
  text-align: center;
  margin-top: 2rem;
}

nav a.router-link-exact-active {
  color: var(--color-text);
}

nav a.router-link-exact-active:hover {
  background-color: transparent;
}

nav a {
  display: inline-block;
  padding: 0 1rem;
  border-left: 1px solid var(--color-border);
}

nav a:first-of-type {
  border: 0;
}

@media (min-width: 1024px) {
  header {
    display: flex;
    place-items: center;
    padding-right: calc(var(--section-gap) / 2);
  }

  .logo {
    margin: 0 2rem 0 0;
  }

  header .wrapper {
    display: flex;
    place-items: flex-start;
    flex-wrap: wrap;
  }

  nav {
    text-align: left;
    margin-left: -1rem;
    font-size: 1rem;

    padding: 1rem 0;
    margin-top: 1rem;
  }
}
</style>
